import { ServiceBaseX } from './../services/order';
import axios from 'axios';

export class TimeManager {
    public static current = new TimeManager();
    constructor() {
        if (!this.serverTimingOffset) {
            const timer = setInterval(() => {
                Promise.resolve().then(() =>
                    ServiceBaseX.prototype.getServerTime().then((data) => {
                        clearInterval(timer);
                        TimeManager.current.serverTimingOffset = new Date().getTime() - data.serverTime;
                    })).catch((ex)=>{})
            }, 5000)
        }
    }
    getServerTime() {
        return this.getLocalTime() - this.serverTimingOffset;
    }
    getLocalTime() {
        return new Date().getTime();
    }
    serverTimingOffset = 0;
}